package com.runshu.newsmartark.util.y.nativelog;

import com.runshu.newsmartark.base.MyApplication;
import com.runshu.newsmartark.util.MacUtils;
import com.runshu.newsmartark.util.y.YFileUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日志系统
 */
public class NLogUtil {
    //网络错误
    public static String Err_NetError = "NetError";
    //程序崩溃
    public static String Err_App_Crash = "AppCrash";
    //人脸识别失败
    public static String Err_Face_Rec_Error = "FaceRecognizeError";
//开柜门超过1小时
    public static String Warn_OPEN_TOO_LONG = "OpenTooLongWarn";
//操作柜子
    public static String INFO_OPERATE_Box = "OperateBox";
    //扫卡开门
    public static String INFO_Scan_Card = "ScanCard";
    //人脸刷脸
    public static String INFO_Face_Recognize = "FaceRecognize";
//APP需要更新
    public static String INFO_App_Need_UPDATE = "NeedUpdateApp";
    //app重启后版本信息
    public static String INFO_RestartAPP_APPINFO = "RestartAppAppInfo";
//同步时间
    public static String INFO_Sync_Record_Time = "SyncRecordTime";
//盘点后货物减少与增加
    public static String INFO_Operate_SerNoGoods = "OperateSerNos";

    public static String LogFileName = MacUtils.getFormatMacAddr() + ".log";

    public static void e(String tag, String msg) {
        new Thread( new Runnable() {
            @Override
            public void run() {
                String log = generateLog( tag, msg, "[E]" );
                YFileUtils.writeFileData( LogFileName, log, MyApplication.getApplication() );
            }
        } ).start();
    }

    public static void i(String tag, String msg) {
        new Thread( new Runnable() {
            @Override
            public void run() {
                String log = generateLog( tag, msg, "[I]" );
                YFileUtils.writeFileData( LogFileName, log, MyApplication.getApplication() );
            }
        } ).start();
    }

    public static void w(String tag, String msg) {
        new Thread( new Runnable() {
            @Override
            public void run() {
                String log = generateLog( tag, msg, "[W]" );
                YFileUtils.writeFileData( LogFileName, log, MyApplication.getApplication() );
            }
        } ).start();
        
        
    }

    private static String generateLog(String tag, String msg, String e) {
        SimpleDateFormat myLogSdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        String needWriteMessage = myLogSdf.format( new Date() ) + "    " + e + "    " + tag + "    " + msg + "\n\r";
        return needWriteMessage;
    }
}
